﻿@using Microsoft.AspNetCore.Components.Forms
@using Covenant.Models.Covenant

<EditForm Model="CovenantUserRegister" OnValidSubmit="OnFormSubmit">
    <DataAnnotationsValidator />
    <div class="form-group">
        <label for="UserName">UserName</label>
        <input id="UserName" name="UserName" @bind="CovenantUserRegister.UserName" class="form-control" @attributes="InputAttributes">
        <div class="text-danger"><ValidationMessage For="() => CovenantUserRegister.UserName" /></div>
    </div>
    <div class="form-group">
        <label for="Password">Password</label>
        <input type="password" id="Password" name="Password" @bind="CovenantUserRegister.Password" class="form-control" disabled="@Disabled">
        <div class="text-danger"><ValidationMessage For="() => CovenantUserRegister.Password" /></div>
    </div>
    <div class="form-group">
        <label for="ConfirmPassword">Confirm Password</label>
        <input type="password" id="ConfirmPassword" name="ConfirmPassword" @bind="CovenantUserRegister.ConfirmPassword" class="form-control" disabled="@Disabled">
        <div class="text-danger"><ValidationMessage For="() => CovenantUserRegister.ConfirmPassword" /></div>
    </div>
    <button type="submit" class="btn btn-primary" disabled="@Disabled">
        @ChildContent
    </button>
</EditForm>

@code {
    [Parameter]
    public CovenantUserRegister CovenantUserRegister { get; set; }

    [Parameter]
    public bool Disabled { get; set; } = false;

    [Parameter]
    public RenderFragment ChildContent { get; set; }

    [Parameter]
    public EventCallback<CovenantUserRegister> OnSubmit { get; set; }

    [Parameter(CaptureUnmatchedValues = true)]
    public Dictionary<string, object> InputAttributes { get; set; }

    private async Task OnFormSubmit()
    {
        await this.OnSubmit.InvokeAsync(this.CovenantUserRegister);
    }
}